package com.gd.luxiaoyu.moduels.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gd.luxiaoyu.Constant;
import com.gd.luxiaoyu.moduels.entity.PictrueTableEntity;
import com.gd.luxiaoyu.moduels.service.PictrueTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;

/**
 * @author xubinbin
 * @email xbb0220@163.com
 * @date 2020-03-07 23:26:03
 */
@RestController
@RequestMapping("right/pictruetable")
public class PictrueTableController {
    @Autowired
    private PictrueTableService pictrueTableService;
    Constant constant = new Constant();

    /**
     * 查询所有的图片信息
     */
    @RequestMapping("/list")
    @ResponseBody
    public Map<String, Object> list(Page<PictrueTableEntity> pictrueTableEntityPage, PictrueTableEntity pictrueTableEntity) {
        IPage<PictrueTableEntity> page = pictrueTableService.getAllPicture(pictrueTableEntityPage, pictrueTableEntity);
        Map<String, Object> map = new HashMap<>();
        map.put("toals", page.getTotal());
        map.put("rows", page.getRecords());
        return map;
    }
    /*
     * sava添加新的图片
     * */

    @RequestMapping("/save")
    @ResponseBody
    public R<?> save(PictrueTableEntity pictrueTableEntity) {
        boolean save = pictrueTableService.save(pictrueTableEntity);
        return save ? R.ok(constant.SUCCESSFUL) : R.failed(constant.FAIL);
    }
    /*
    * 修改 图片信息
    * */
    @RequestMapping("/update")
    @ResponseBody
    public  R<?> update(PictrueTableEntity pictrueTableEntity){
        boolean update = pictrueTableService.updateById(pictrueTableEntity);
        return update ? R.ok(constant.SUCCESSFUL) : R.failed(constant.FAIL);
    }


    /*
    * 一般系统会为 用户默认一张图片  可以删除 删除后就会显示默认图片
    * 这里是通过图片id删除
    * */
    @RequestMapping("/delete")
    @ResponseBody
    public R<?> delete(PictrueTableEntity pictrueTableEntity){
        boolean delete = pictrueTableService.removeById(pictrueTableEntity.getId());
        return  delete ? R.ok(constant.SUCCESSFUL) : R.failed(constant.FAIL);
    }

    /*
     * 一般系统会为 用户默认一张图片  可以删除 删除后就会显示默认图片
     * 这里是通过用户id删除
     * */
    @RequestMapping("/deleteByUserId")
    @ResponseBody
    public R<?> deleteByUserId(PictrueTableEntity pictrueTableEntity){
        boolean delete = pictrueTableService.removeById(pictrueTableEntity.getUid());
        return  delete ? R.ok(constant.SUCCESSFUL) : R.failed(constant.FAIL);
    }
    /*
     * 一般系统会为 用户默认一张图片  可以删除 删除后就会显示默认图片
     * 这里是通过APP的id删除
     * */
    @RequestMapping("/deleteByAppId")
    @ResponseBody
    public R<?> deleteByAppId(PictrueTableEntity pictrueTableEntity){
        boolean delete = pictrueTableService.removeById(pictrueTableEntity.getAppid());
        return  delete ? R.ok(constant.SUCCESSFUL) : R.failed(constant.FAIL);
    }

    /*
     * 一般系统会为 用户默认一张图片  可以删除 删除后就会显示默认图片
     * 这里是通过开发商的id删除
     * */
    @RequestMapping("/deleteByCustomerId")
    @ResponseBody
    public R<?> deleteByCustomerId(PictrueTableEntity pictrueTableEntity){
        boolean delete = pictrueTableService.removeById(pictrueTableEntity.getCid());
        return  delete ? R.ok(constant.SUCCESSFUL) : R.failed(constant.FAIL);
    }

}
